package com.lagou.edu.service.impl;


import com.lagou.edu.dao.UserInfoDao;
import com.lagou.edu.pojo.LagouAuthCode;
import com.lagou.edu.pojo.UserInfo;
import com.lagou.edu.service.UserInfoService;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;


/**
 * @Author wyx
 * @Date 2020/5/5 23:48
 */
@Service
public class UserInfoServiceImpl implements UserInfoService {

    @Autowired
    UserInfoDao userInfoDao;



    @Override
    public String addUserInfo(UserInfo userInfo,String code,List<LagouAuthCode> lagouAuthCodes)  {

        LagouAuthCode lagouAuthCode = lagouAuthCodes.get(0);
        Date expiretime = lagouAuthCode.getExpiretime();
        Date now= new Date();

        //验证码过期时
        if (now.compareTo(expiretime)==1){
            return "验证码已失效，请重新发送！";
        }

        if (lagouAuthCodes.size()>0){
            if (lagouAuthCodes.get(0).getCode().equals(code)){
                userInfoDao.save(userInfo);
                return "保存成功";
            }
            return "保存失败，验证码错误";
        }
        return "保存失败，验证码错误";
    }


    @Override
    public UserInfo findUserInfo(String email) {
        return userInfoDao.findByEmail(email);
    }


}